import instance from "./axios"
import type {AxiosRequestConfig} from "axios";

// 定义请求参数的类型
interface RequestParams {
    method: 'get' | 'post' | 'put' | 'delete';
    url: string;
    data?: any; // 或者你可以为 data 指定一个更具体的类型
    config?: AxiosRequestConfig; // 引入 AxiosRequestConfig 类型
}

const axios = ({
                   method,
                   url,
                   data,
                   config
               }: RequestParams) => {
    if (method == 'post') {
        return instance.post(url, data, {...config})
    } else if (method == 'get') {
        return instance.get(url, {
            params: data,
            ...config
        })
    } else if (method == 'delete') {
        return instance.delete(url, {
            params: data,
            ...config
        },)
    } else if (method == 'put') {
        return instance.put(url, data, {...config})
    } else {
        console.error('未知的method' + method)
        return false
    }
}
export default axios